#*******************************************************************
#* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        *
#*                                                                 *
#*  NOTE      = http协议分析
#*  DATE      =
#*******************************************************************

NULLSTRING              :=
SPACE                   := $(NULLSTRING) # end of the line
PROTOCOL_ANALYZER_DIR   := $(shell T_DIRNAME=`dirname $(CURDIR)`;T_BASENAME=`basename $(CURDIR)`;until [[ $$T_DIRNAME = "/" || $$T_BASENAME = "protocol_analyzer" ]];do T_DIRNAME=`dirname $$T_DIRNAME`;T_BASENAME=`basename $$T_DIRNAME`;done;echo $$T_DIRNAME)
MODULE                  := $(firstword $(subst /,$(SPACE),$(subst $(PROTOCOL_ANALYZER_DIR)/test/,,$(CURDIR))))
include                 $(PROTOCOL_ANALYZER_DIR)/test/comm/Makefile_comm.mk
include                 $(PROTOCOL_ANALYZER_DIR)/dist/dev/include/apmmodule/Makefile_comm.mk

INCLUDES                = -I. -I$(LIB_I_APM_COMM) -I$(LIB_I_APM_MODULE) -I$(LIB_I_TEST_COMM) -I$(PROTOCOL_ANALYZER_DIR)/src/exec/framework
LIBS                    = -lzlog -lpthread -luuid -lcunit -ljson-c `xml2-config --libs`
CFLAGS                  = -fPIC `xml2-config --cflags`

CFLAGS                  += $(CFLAGS_EXT)
LIBS                    += $(LIBS_EXT)

TEST_TARGETS            = test_$(MODULE)

MODULE_VERSION          := $(COMM_FRAMEWORK_VER).$(L7_VERSION)
TARGET_LIB_VER          := $(L7_NAME)_$(MODULE_VERSION).so

TEST_SOURCE_FILES       := $(shell find . -name "*.c" -o -name "*.h" | sed 's|./||')

.PHONY:clean
all: recompile_apm_comm recompile_apm_module $(TEST_TARGETS) run

recompile_apm_comm:
	$(MAKE) -C $(APM_COMM_SRC_DIR) clean
	$(MAKE) CFLAGS_UTEST=-DAPMTEST_CUNIT -C $(APM_COMM_SRC_DIR)
	$(MAKE) -C $(APM_COMM_SRC_DIR) install

recompile_apm_module:
	$(MAKE) -C $(APM_MODULE_SRC_DIR) clean
	$(MAKE) CFLAGS_UTEST=-DAPMTEST_CUNIT -C $(APM_MODULE_SRC_DIR)
	$(MAKE) -C $(APM_MODULE_SRC_DIR) install

$(LIB_A_APM_FRAME): $(LIB_A_APM_FRAME_OBJS)
	echo $^ | xargs ar crv $(LIB_A_APM_FRAME) && ranlib $(LIB_A_APM_FRAME)

$(TEST_TARGETS): $(TEST_SOURCE_FILES) $(COMM_TEST_CFILES) $(LIB_A_APM_FRAME)
	$(CX) $(CFLAGS) $(COMM_TEST_CFILES) $(filter %.c,$(TEST_SOURCE_FILES)) $(LIB_A_APM_MODULE) $(LIB_A_APM_COMM) $(LIB_A_APM_FRAME) -o $@ $(INCLUDES) $(LIBS)

run:
	$(VG) ./$(TEST_TARGETS)

clean:
	find . -name "*.o" | xargs rm -f
	rm -f $(TEST_TARGETS) $(COMM_SRC_MODULE_DIR)/$(TARGET_LIB_VER)

#EOF
